package com.weaver.openapi.service;

import com.weaver.openapi.pojo.task.params.*;
import com.weaver.openapi.pojo.task.res.*;
import com.weaver.openapi.util.*;
import java.util.*;
import cn.hutool.http.*;
import com.weaver.openapi.pojo.*;
import com.alibaba.fastjson.*;
import com.weaver.openapi.pojo.task.res.vo.*;

public class TaskService
{
    public static TaskResultVo createTaskV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("userid", taskVo.getUserid());
        paramMap.put("name", taskVo.getName());
        paramMap.put("content", taskVo.getContent());
        paramMap.put("group", taskVo.getGroup());
        paramMap.put("commonFormData", taskVo.getCommonFormData());
        paramMap.put("formId", taskVo.getFormId());
        paramMap.put("taskTypeFormData", taskVo.getTaskTypeFormData());
        paramMap.put("parentId", taskVo.getParentId());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/create").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static MessageResult deleteTaskV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("userid", taskVo.getUserid());
        paramMap.put("id", taskVo.getId());
        paramMap.put("deleteType", taskVo.getDeleteType());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/delete").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (MessageResult)JSONObject.parseObject(resJson, (Class)MessageResult.class);
    }
    
    public static MessageResult updateTaskV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("userid", taskVo.getUserid());
        paramMap.put("id", taskVo.getId());
        paramMap.put("propertyName", taskVo.getPropertyName());
        paramMap.put("propertyValue", taskVo.getPropertyValue());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/update").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (MessageResult)JSONObject.parseObject(resJson, (Class)MessageResult.class);
    }
    
    public static TaskResultVo queryTaskInfoV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("id", taskVo.getId());
        paramMap.put("containsSub", taskVo.isContainsSub());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/task/v2/info").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static TaskResultVo queryTasksV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("beginDateStr", taskVo.getBeginDateStr());
        paramMap.put("endDateStr", taskVo.getEndDateStr());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/queryTasks").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static TaskResultVo queryMineInfoV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("userid", taskVo.getUserid());
        paramMap.put("type", taskVo.getType());
        paramMap.put("queryParams", taskVo.getQueryParams());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/mineInfo").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static TaskResultVo queryTaskTypesV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/task/v2/queryTaskTypes").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static TaskResultVo queryFormInfoByTaskTypeV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("taskTypeId", taskVo.getTaskTypeId());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/task/v2/queryFormInfoByTaskType").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static TaskResultVo queryUpdateTasksV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("startTime", taskVo.getStartTime());
        paramMap.put("endTime", taskVo.getEndTime());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/queryUpdateTasks").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static TaskResultVo queryRealWorkingTimesV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("startTime", taskVo.getStartTime());
        paramMap.put("endTime", taskVo.getEndTime());
        paramMap.put("dateType", taskVo.getDateType());
        paramMap.put("bmFollowParent", taskVo.getBmFollowParent());
        paramMap.put("workingTimeDate", taskVo.getWorkingTimeDate());
        paramMap.put("taskId", taskVo.getTaskId());
        paramMap.put("userId", taskVo.getUserId());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/queryRealWorkingTimes").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static TaskResultVo fillRealWorkingTimesV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("fillRecords", JSONObject.toJSONString((Object)taskVo.getFillRecords()));
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/fillRealWorkingTimes").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static TaskResultVo updateRealWorkingTimesV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("userId", taskVo.getUserId());
        paramMap.put("fillRecords", JSONObject.toJSONString((Object)taskVo.getFillRecords()));
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/fillRealWorkingTimes").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (TaskResultVo)JSONObject.parseObject(resJson, (Class)TaskResultVo.class);
    }
    
    public static MessageResult deleteRealWorkingTimesV2(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("userId", taskVo.getUserId());
        paramMap.put("fillRecordIds", JSONObject.toJSONString((Object)taskVo.getFillRecordIds()));
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/task/v2/deleteRealWorkingTimes").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (MessageResult)JSONObject.parseObject(resJson, (Class)MessageResult.class);
    }
    
    public static ApiResult<BatchResultVo> createTaskV3(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/json");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("userid", taskVo.getUserid());
        paramMap.put("propertyDataList", taskVo.getPropertyDataList());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/api/task/v3/create").body(JSON.toJSONString((Object)paramMap)).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static ApiResult<BatchOpResultVo> updateTaskV3(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/json");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("userid", taskVo.getUserid());
        paramMap.put("propertyDataList", taskVo.getPropertyDataList());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/api/task/v3/update").body(JSON.toJSONString((Object)paramMap)).headerMap((Map)headers, true)).execute().body();
        return transferListResult(resJson);
    }
    
    public static ApiResult<BatchOpResultVo> changeableListV3(final TaskVo taskVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/json");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", taskVo.getAccessToken());
        paramMap.put("userid", taskVo.getUserid());
        paramMap.put("propertyDataList", taskVo.getPropertyDataList());
        paramMap.put("id", taskVo.getId());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/api/task/v3/status/changeableList").body(JSON.toJSONString((Object)paramMap)).headerMap((Map)headers, true)).execute().body();
        return transferListResult(resJson);
    }
    
    public static ApiResult<BatchResultVo> transferResult(final String resJson) {
        final JSONObject jsonObject = JSONObject.parseObject(resJson);
        final BatchResultVo data = (BatchResultVo)jsonObject.getObject("data", (Class)BatchResultVo.class);
        final String code = (String)jsonObject.getObject("code", (Class)String.class);
        final String msg = (String)jsonObject.getObject("msg", (Class)String.class);
        final boolean status = (boolean)jsonObject.getObject("status", (Class)Boolean.class);
        final boolean fail = (boolean)jsonObject.getObject("fail", (Class)Boolean.class);
        final ApiResult<BatchResultVo> normalRes = new ApiResult<BatchResultVo>();
        normalRes.setData(data);
        normalRes.setCode(code);
        normalRes.setMsg(msg);
        normalRes.setStatus(status);
        normalRes.setFail(fail);
        return normalRes;
    }
    
    public static ApiResult<BatchOpResultVo> transferListResult(final String resJson) {
        final JSONObject jsonObject = JSONObject.parseObject(resJson);
        final BatchOpResultVo data = (BatchOpResultVo)jsonObject.getObject("data", (Class)BatchOpResultVo.class);
        final String code = (String)jsonObject.getObject("code", (Class)String.class);
        final String msg = (String)jsonObject.getObject("msg", (Class)String.class);
        final boolean status = (boolean)jsonObject.getObject("status", (Class)Boolean.class);
        final boolean fail = (boolean)jsonObject.getObject("fail", (Class)Boolean.class);
        final ApiResult<BatchOpResultVo> normalRes = new ApiResult<BatchOpResultVo>();
        normalRes.setData(data);
        normalRes.setCode(code);
        normalRes.setMsg(msg);
        normalRes.setStatus(status);
        normalRes.setFail(fail);
        return normalRes;
    }
}
